// webpack plugins
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.config.common.js');
let path = require("path");

/**
 * config
 * Reference: http://webpack.github.io/docs/configuration.html
 */
module.exports = webpackMerge(commonConfig, {
  // devtool: 'cheap-module-eval-source-map',
  devtool: 'source-map',
  devServer: {
    inline: true,
    hot: true,
    historyApiFallback: true
  },
  output: {
    path: path.resolve(__dirname, 'build'),
    publicPath: '/',
    filename: 'scripts/[name].js',
    chunkFilename: 'scripts/[id].chunk.js'
  },
  module: {
    rules: [{
        test: /\.ts$/,
        include: path.resolve(__dirname, './src'),
        exclude: /node_modules|aot/g,
        use: [{
            loader: "awesome-typescript-loader",
            options: {
              transpileOnly: true,
              useCache: true
            }
          },
          'angular2-template-loader',
          {
            loader: 'string-replace-loader',
            options: {
              multiple: [{
                search: 'test\.58caimi',
                replace: 'www.58caimi',
                flags: 'ig'
              }]
            }
          }
        ],
        enforce: "pre"
      },
      {
        test: /\.json$/,
        include: path.resolve(__dirname, './src'),
        use: [
          "json-loader",
          {
            loader: 'string-replace-loader',
            options: {
              multiple: [{
                search: 'test\.58caimi',
                replace: 'www.58caimi',
                flags: 'ig'
              }]
            },
          }
        ],
        enforce: "pre"
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin('styles/[name].css'),
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.DefinePlugin({
      BUILD_IN_PRODUCTION: JSON.stringify(false)
    }),
  ],
  node: {
    fs: "empty"
  }
});